<?php
namespace app\home\controller;

use common\controller\Base;
use think\Db;
use think\Request;
use think\Cache;

class Index extends Base
{
    public function index()
    {
        $this->redirect('http://monicaquartz.com');

        return $this->fetch();
    }

    public function goods($id){

        if($id){
            $item = Db::table('goods')->where('id',$id)->find();
            $data = Db::table('goods')
                ->alias('g')
                ->join('goods_images i', 'g.id=i.goods_id')
                ->where(['g.id' => $id])
                ->select();

            $this->assign('data', $data);
            $this->assign('item', $item);
            $this->assign('loopedSlides' , ($item['sum_img'] < 4 ? $item['sum_img']:4));

            $music = Cache::get('music');
            $musicLen = $music ? count($music) - 1:1;
            $key = rand(0, $musicLen);

            $this->assign('music', (isset($music[$key])?$music[$key]:0));
        }else{
            $this->error('非法操作！');
        }

        return $this->fetch();
    }

}
